//
//  NearFoodTableViewCell.m
//  Food & Delights
//
//  Created by dlios on 15-7-13.
//  Copyright (c) 2015年 李志远. All rights reserved.
//

#import "NearFoodTableViewCell.h"

@implementation NearFoodTableViewCell

- (void)dealloc
{
    [super dealloc];
    [_place_name release];
    [_category release];
    [_img release];
    [_distane release];
    [_model release];
    [_starView release];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.category = [[UILabel alloc] init];
        self.category.font = [UIFont systemFontOfSize:14];
        self.category.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.category];
        
        self.place_name = [[UILabel alloc] init];
        self.place_name.font = [UIFont systemFontOfSize:16];
        self.place_name.textColor = [UIColor redColor];
        [self.contentView addSubview:self.place_name];
        
        self.distane = [[UILabel alloc] init];
        self.distane.font = [UIFont systemFontOfSize:14];
        self.distane.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.distane];
        self.img = [[UIImageView alloc] init];
        self.img.layer.cornerRadius = 30;
        self.img.layer.masksToBounds = YES;
        [self.contentView addSubview:self.img];
        
        self.starView = [[StarView alloc] initWithFrame:CGRectMake(80, 60, 100, 20)];
        [self.contentView addSubview:self.starView];

    }
    
    return self;
}

- (void)layoutSubviews
{
    
    [super layoutSubviews];
    
    self.img.frame = CGRectMake(10, 20, 60, 60);
    self.category.frame = CGRectMake(80, 20,80, 20);
    self.place_name.frame = CGRectMake(80, 40, 200, 20);
    self.distane.frame = CGRectMake(150, 20, 100, 20);
}

- (void)setModel:(NearFoodModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    if ([model.category isEqualToString:@"烧烤"]) {
        self.img.image = [UIImage imageNamed:@"shaokao"];
    }else if ([model.category isEqualToString:@"火锅"]) {
        self.img.image = [UIImage imageNamed:@"huoguo"];
    }else if ([model.category isEqualToString:@"日韩料理"]) {
        self.img.image = [UIImage imageNamed:@"ribenliaoli"];
    }else if ([model.category isEqualToString:@"东北菜"]) {
        self.img.image = [UIImage imageNamed:@"dongbeicai"];
    }else if ([model.category isEqualToString:@"川菜"]){
        self.img.image = [UIImage imageNamed:@"chuancai"];
    }else if ([model.category isEqualToString:@"湘菜"]){
        self.img.image = [UIImage imageNamed:@"xiangcai"];
    }else if ([model.category isEqualToString:@"江苏菜"]){
        self.img.image = [UIImage imageNamed:@"jiangsu"];
    }else if ([model.category isEqualToString:@"粤菜"]){
        self.img.image = [UIImage imageNamed:@"yuecai"];
    }else if ([model.category isEqualToString:@"海鲜"]){
        self.img.image = [UIImage imageNamed:@"haixian"];
    }else if ([model.category isEqualToString:@"小吃快餐"]){
        self.img.image = [UIImage imageNamed:@"xiaochikuaican"];
    }else if ([model.category isEqualToString:@"面包甜点"]){
        self.img.image = [UIImage imageNamed:@"mianbaotiandian"];
    }else if ([model.category isEqualToString:@"民族菜"]){
        self.img.image = [UIImage imageNamed:@"minzucai"];
    }else{
        self.img.image = [UIImage imageNamed:@"qita"];
    }
    
    self.category.text = model.category;
    self.place_name.text = model.place_name;
    
    if (model.distance < 200) {
        self.distane.text = @"200米内";
        
    }else if (model.distance > 200 && model.distance < 500){
        self.distane.text = @"500米内";
    }else if (model.distance >500 && model.distance <1000){
        self.distane.text = @"1000米内";
    }else
    {
        self.distane.text = @"1000米以外";
    }
    
    [_starView createViewWithScore:[model.star floatValue]];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
